<template>
  <div class="container">
    <topSearch
      :form="form"
      :showAdd="checkPermission(['prepareLineCreate'])"
      @addItem="addItem"
      @searchlist="searchlist"
      @resetform="resetform"
    ></topSearch>

    <el-row>
      <el-table
        :data="tableData"
        border
        style="width: 100%; margin-top: 20px"
        size="small"
      >
        <el-table-column
          prop="title"
          label="线路名称"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="city_id"
          label="城市"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="线路详情"
          width="400"
        >
          <template slot-scope="scope">
            <el-tooltip placement="top" popper-class="contentTips">
              <div slot="content">
                <span><span  class="title">起始点：</span>{{ scope.row.start_point.title }}<span v-if="scope.row.start_point.isPhoto" class="el-icon-camera-solid marginLS"></span></span><br/>
                <span v-if="scope.row.more_point.length>0"><span  class="title">途经点：</span><span v-for="(p, i) in scope.row.more_point"><span :class="i!=0?'marginL':''" v-if="p">{{ p.title }}</span><span v-if="p.isPhoto" class="el-icon-camera-solid marginLS"></span><br/></span></span>
                <span><span  class="title">目的地：</span>{{ scope.row.end_point }}</span>
              </div>
              <div class="tips">
                <span
                :style="{
                  color: scope.row.start_point.isPhoto == 1 ? '#1bbc9b' : '',
                }"
                >{{ scope.row.start_point.title }}</span
              ><span class="el-icon-caret-right" style="margin: 0 10px"></span>
              <span v-for="(p, i) in scope.row.more_point" v-if="scope.row.more_point.length>0"
                ><span  v-if="i != 0"  :class="i != 0 ?'el-icon-caret-right':''"  style="margin: 0 10px"></span
                ><span
                  :style="{ color: p.isPhoto == 1 ? '#1bbc9b' : '' }"
                  v-if="p"
                  >{{ p.title }}</span
                ></span
              ><span class="el-icon-caret-right" style="margin: 0 10px" v-if="scope.row.more_point.length>0"></span>
              <span
                :style="{
                  color: scope.row.end_point.isPhoto == 1 ? '#1bbc9b' : '',
                }"
                >{{ scope.row.end_point.title }}</span
              >
              </div>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column
          prop="price"
          label="价格（元）"
 
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="txt"
          label="备注"

          show-overflow-tooltip
        ></el-table-column>

        <el-table-column prop="date" label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="editItem(scope.row)"
              v-if="checkPermission(['prepareLineUpdate'])"
              >编辑</el-button
            >
            <el-button
              type="text"
              @click="deleteTableItem(scope.row)"
              v-if="checkPermission(['prepareLineDelete'])"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-row>
        <el-col :span="24" class="pagination">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20]"
            :page-size="10"
            background
            :current-page.sync="page"
            layout="total, sizes, prev, pager, next"
            :total="pagination.total"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </el-row>
    <!-- 弹框 -->
    <subdialog
      :isshowDialog="isshowDialog"
      :dialogTitle="dialogTitle"
      :formType="formtype"
      :cityoptions="cityoptions"
      @confirm="confirm"
      @closedialog="closedialog"
      :dialogdata="dialogdata"
    ></subdialog>
  </div>
</template>

<script type="text/javascript">
import {
  prepareLine,
  prepareLineRead,
  prepareLineDelete,
} from "@/api/dataPreparation";
import subdialog from "./components/dialog";
import checkPermission from "@/utils/permission"; // 权限判断函数
import topSearch from "@/components/topSearch";
import { commonGetCity } from "@/api/examplace";
export default {
  data() {
    return {
      isshowDialog: false,
      dialogTitle: "新增",
      formtype: 0,
      page: 1,
      rows: 10,
      form: {
        state: null,
      },
      tableData: [],
      category: [],
      cityoptions: [],
      pagination: {},
      dialogdata: null,
    };
  },
  components: {
    subdialog,
    topSearch,
  },
  created() {
    this.getData();
    this.getcommonGetCity();
  },
  methods: {
    checkPermission,

    searchlist() {
      (this.page = 1), this.getData();
    },
    resetform() {
      this.getData();
    },
    handleSizeChange(val) {
      this.rows = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    },
    //详情
    async getquestionRead(id) {
      let data = await prepareLineRead({ id: id });
      this.dialogdata = data.data;
    },
    //城市下拉
    async getcommonGetCity() {
      let data = await commonGetCity();
      this.cityoptions = data.data;
    },

    //获取下拉
    async getprepareLineOption() {
      let data = await prepareLineOption();
      this.prepareLineOption = data.data;
    },
    //新增
    addItem() {
      this.isshowDialog = true;
      this.dialogTitle = "新增";
      this.formtype = 0;
    },
    //删除
    async deleteTableItem(val) {
      let data = await prepareLineDelete({ id: val.id });
      if (data.code == "0000") {
        this.$message({
          type: "success",
          message: data.msg,
        });
        this.getData();
      }
    },
    //编辑
    editItem(val) {
      this.isshowDialog = true;
      this.dialogTitle = "编辑";
      this.formtype = 1;
      this.getquestionRead(val.id);
    },

    //提交成功
    confirm() {
      this.isshowDialog = false;
      this.getData();
    },
    closedialog() {
      this.isshowDialog = false;
    },
    //获取列表
    async getData() {
      let params = {
        page: this.page,
        rows: this.rows,
      };
      if (this.form.keyWord) {
        params.keyword = this.form.keyWord;
      }
      console.log(params);
      let data = await prepareLine(params);
      console.log(data);
      let datainfo = data.data;
      this.tableData = datainfo.list;
      this.pagination = datainfo.page;
    },
  },
  mounted() {},
};
</script>
<style lang="scss">

  .contentTips{
    line-height: 2.2;
    .title{display: inline-block;width: 50px ; }
    .marginL{
      margin-left: 50px;
    }
    .marginLS{
      margin-left: 10px;
    }
  }
</style>
<style lang="scss" scoped>
::v-deep{
  .tips{
    overflow: hidden;text-overflow:ellipsis;
 -o-text-overflow:ellipsis;
 -webkit-text-overflow:ellipsis;
 -moz-text-overflow:ellipsis;
 white-space:nowrap;
  }
  .marginLS{
      margin-left: 10px;
    }

}
</style>
